package com.qianyu.api.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianyu.core.entity.base.Result;
import com.qianyu.core.entity.bean.OrderPay;
import com.qianyu.core.entity.bean.PayWay;
import com.qianyu.core.entity.bean.WalletAccount;
import com.qianyu.core.entity.dto.OrderPayDto;
import com.qianyu.core.helper.LoginHelper;
import com.qianyu.core.service.OrderPayService;
import com.qianyu.core.service.PayWayService;
import com.qianyu.core.service.WalletAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(tags = "前台管理-充值中心", description = "wangzhicheng")
@RestController
@RequestMapping("/front/orderPay")
@RequiredArgsConstructor
public class FrontOrderPayController {

    private final OrderPayService orderPayService;

    private final PayWayService payWayService;

    private final WalletAccountService walletAccountService;

    /**
     * 查询支付方式
     */
    @GetMapping("/getPayWay")
    @ApiOperation(value = "查询支付方式")
    Result<List<PayWay>> getPayWay() {
        return Result.success(payWayService.getPayWay());
    }


    /**
     * 查询账户信息
     */
    @GetMapping("/getAccount")
    @ApiOperation(value = "查询账户信息")
    Result<WalletAccount> getAccount(){
        return Result.success(walletAccountService.getAccount());
    }

    /**
     * 充值中心
     */
    @PostMapping(value = "/saveOrder")
    @ApiOperation(value = "充值")
    Result<String> saveOrder(@RequestBody @Validated OrderPayDto.OrderPaySaveDto dto, HttpServletRequest request) {
        orderPayService.saveOrder(dto, request);
        return Result.success();
    }

    /**
     * 充值记录
     */
    @PostMapping(value = "/pageOrderPay")
    @ApiOperation(value = "充值记录")
    Result<Page<OrderPay>> pageOrderPay(@RequestBody @Validated OrderPayDto.OrderPayPageDto dto) {
        return Result.success(orderPayService.pageOrderPay(dto, LoginHelper.getUserId()));
    }
}
